package Problem;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Sky extends JLabel implements ActionListener {
    Earth earth;
    Timer timer;
    double pointx[]=new double[360],pointy[]=new double[360];
    int w = 400,h=400,i=0;
    Sky(){
        setLayout(new FlowLayout());
        timer = new Timer(100, this);
        setPreferredSize(new Dimension(w, h));
        earth = new Earth();
        add(earth);
        earth.setPreferredSize(new Dimension(200, 200));
        pointx[0]=0;
        pointy[0]=h/2;
        double angle = 1*Math.PI/180;
        for (int i = 0; i < 359; i++) {
            pointx[i+1] =pointx[i]*Math.cos(angle) - Math.sin(angle)*pointy[i];
            pointy[i+1]=pointy[i]*Math.cos(angle)+pointx[i]*Math.sin(angle);
        }
        for (int i = 0; i < 360; i++) {
            pointx[i] =0.5*pointx[i]+w/2;
            pointy[i]=0.5*pointy[i]+h/2;

        }
        timer.start();
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        i =(i+1)%360;
        earth.setLocation((int)pointx[i]-100, (int)pointy[i]-100);

    }


}

